$(function () {
    var item = GetQueryString("item");
    var sort = GetQueryString("sort");

//查询列表页
     var sel = $.Params.create();
    sel.addParams("page", 0);
    sel.addParams("rows", rows);
    sel.addParams("item", item);
    sel.addParams("sort", sort);
    getData();
    //搜索查询
    $("#searchBtn").on("click",function(){
        var pTitle = $("#searchVal").val();
         if(pTitle != ""){
            sel.addParams("pTitle",pTitle);
        }else{
            sel.addParams("pTitle",undefined);
        }
        getData();
    })

    //删除记录
    $("#delBtn").on("click",function(){
        var params = getCheckData();
        if(params != ""){
            if(confirm("确定要删除吗！")){
                var del = $.Params.create();
                del.ajax("delete",getAdminIP()+"binglis?params="+params,function(data){
                    if(data.success){
                        alert(data.msg);
                        getData();
                    }else{
                        alert(data.msg);
                    }
                })
            }
        }else{
            alert("请选择要删除的记录！");
        }
    })

    //添加按钮
    $("#addDataBtn").on("click",function(){
        window.location.href = "wzzBlAdd.html?item="+item+"&sort="+sort;
    })

   

    //判断checkbox状态
    $("#selAll").on("click", function () {
        if (!$(this).attr("checked")) {
            $("input[type=checkbox]").attr("checked", "checked")
        } else {
            $("input[type=checkbox]").removeAttr("checked");
        }
    })
    //列表页
    function getData() {
        getPageData("get", sel, getAdminIP() + "binglis", function (data) {
            if (data.success) {
                var videoHtml = "";
                if (data.total > 0) {
                    $.each(data.result, function (i, val) {
                        var blImg = getIP() + "data/blCover/" + val.titlePic;
                        var attachType = "";
                        if (val.attachType == "1") {
                            attachType="视频";
                        }else if(val.attachType == "2"){
                            attachType="PPT";
                        }
                        videoHtml += "<tr role='row' class='odd'>" +
                            "<td><input type='checkbox' eid='" + val.id + "' onclick='getCheck(this)' class='classOption'></td>" +
                            "<td><img src='" + blImg + "' style='width:100%' /></td >" +
                            "<td>" + val.expertName + "</td >" +
                            "<td>" + val.expertHospital + "</td>" +
                            "<td>" + val.title + "</td>" +
                            "<td>" + attachType + "</td>" +
                            "<td>" + val.createTime + "</td>" +
                            "<td><button type='button' onClick='selComment(\"" + val.id + "\",\""+item+"\",\""+sort+"\")' class='btn btn-primary'>查看评论</button><button type='button' onClick='update(\"" + val.id + "\",\""+item+"\",\""+sort+"\")' class='btn btn-primary'>修改</button><button type='button' onClick = 'setTop(\"" + val.id + "\")' class='btn btn-primary'>置顶</button></td>" +
                            "</tr>";
                    })
                } else {
                    videoHtml = "";
                }
                $("#listContainer").html(videoHtml);
            } else {
                alert(data.msg);
            }
        })
    }

    //置顶
    setTop = function(eid){
        var topSel = $.Params.create();
        topSel.ajax("put",getAdminIP()+"binglis/"+eid,function(data){
            if(data.success){
                getData();
            }else{
                alert(data.msg);
            }
        })
    }
})

//修改
function update(eid,item,sort){
    window.location.href = "wzzBlUpdate.html?eid="+eid+"&item="+item+"&sort="+sort;
}


//查看评论
function selComment(eid,item,sort){
    window.location.href = "wzzBlPlList.html?titleId="+eid+"&item="+item+"&sort="+sort;
}